1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.util.concurrent;
18
19 import com.google.common.base.Function;
20
21 import java.lang.reflect.UndeclaredThrowableException;
22
23
24
25
26
27
28 public class FuturesTransformTest
29 extends AbstractChainedListenableFutureTest<String> {
30 private static final String RESULT_DATA = "SUCCESS";
31
32 @Override protected ListenableFuture<String> buildChainingFuture(
33 ListenableFuture<Integer> inputFuture) {
34 return Futures.transform(inputFuture,
35 new ComposeFunction());
36 }
37
38 @Override protected String getSuccessfulResult() {
39 return RESULT_DATA;
40 }
41
42 private class ComposeFunction
43 implements Function<Integer, String> {
44 @Override
45 public String apply(Integer input) {
46 if (input.intValue() == VALID_INPUT_DATA) {
47 return RESULT_DATA;
48 } else {
49 throw new UndeclaredThrowableException(EXCEPTION);
50 }
51 }
52 }
53
54 public void testFutureGetThrowsFunctionException() throws Exception {
55 inputFuture.set(EXCEPTION_DATA);
56 listener.assertException(EXCEPTION);
57 }
58 }